package com.codesynapse.controller;

import com.codesynapse.service.AIModelService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

@Slf4j
@Controller
@RequiredArgsConstructor
public class CodeCompletionController {

    private final AIModelService aiModelService;

    @MessageMapping("/complete")
    @SendTo("/topic/completion")
    public String complete(String prompt) {
        log.info("收到代码补全请求: {}", prompt);
        try {
            String result = aiModelService.generateCompletion(prompt);
            log.info("生成补全结果: {}", result);
            return result;
        } catch (Exception e) {
            log.error("代码补全出错", e);
            return "生成代码时发生错误: " + e.getMessage();
        }
    }
} 